<?php

declare(strict_types=1);

namespace App\Listener\Task;

use Hyperf\Crontab\Event\FailToExecute;
use Hyperf\Di\Annotation\Inject;
use Hyperf\Event\Annotation\Listener;
use Psr\Container\ContainerInterface;
use Hyperf\Event\Contract\ListenerInterface;
use Psr\SimpleCache\CacheInterface;

#[Listener]
class FailToExecuteCrontabListener implements ListenerInterface
{
    #[Inject]
    protected CacheInterface $cache;

    public function __construct()
    {
    }

    /**
     * @return string[]
     */
    public function listen(): array
    {
        return [
            FailToExecute::class
        ];
    }

    /**
     * @param object $event
     */
    public function process(object $event): void
    {
        logs($event->crontab->getName());
        logs($event->throwable->getMessage());
        logs($event->throwable->getTraceAsString());

        $keyName = 'campus_meal_task';
        $this->cache->delete($keyName);
    }
}
